var api = require('../../utils/api.js');
var app = getApp();
Page({
    data: {
        lists: [],
        show:0,
        wind1:0,
        desc:'',
        merch_id:'',
        wind2:0,
        cates:[],
        cate_id:''

    },
    onLoad(ret) {
        var that=this;

        this.setData({
            show:ret.i
        })



        api.post({
            url: 'index/getcate',
            data: {},
            success: data => {
                that.setData({
                    cates:data.data
                })
            }
        })

    },
    onShow() {
      this.getmymerchlist();
    },

    getmymerchlist(){
        var show=this.data.show;
        var that=this;

        that.setData({
            lists:[]
        })
        api.post({
            url: 'merchlist/getmymerch',
            data: {show:show},
            success: data => {
                that.setData({
                    lists:data.data
                })
            }
        })


    },

    setshow(ret){
        console.log(ret);
        this.setData({
            show:ret.currentTarget.dataset.i
        })

        this.getmymerchlist();
    },

    callphone(ret){
        console.log(ret);
        wx.makePhoneCall({
          phoneNumber: ret.currentTarget.dataset.mobile
        })
    },

    copyphone(ret){
        wx.setClipboardData({
            data: ret.currentTarget.dataset.mobile, 
            success(res) {
                console.log('拷贝成功');
            },
        });
    },

    hidewind(){
        this.setData({
            wind1:0
        })
    },
    windshow(ret){
        var id=ret.currentTarget.dataset.id;

        this.setData({
            wind1:1,
            merch_id:id
        })
    },

    wind2show(ret){
        var id=ret.currentTarget.dataset.id;
        this.setData({
            wind2:1,
            merch_id:id
        })
    },
    getdesc(ret){
        console.log(ret);
        this.setData({
            desc:ret.detail.value
        })
    },
    setdescbyid(){
        console.log('9')
        var merch_id=this.data.merch_id;
        var desc=this.data.desc;
          
        var that=this;

        that.setData({
            wind1:0
        })


        api.post({
            url: 'merchlist/setmerchlisttypes',
            data: {merch_id:merch_id,desc:desc},
            success: data => {

                that.getmymerchlist();
                that.setData({
                    merch_id:'',
                    desc:''
                })

               
            }
        })
    },
    hidewind2(){
        this.setData({
            wind2:0,
            cate_id:0
        })
    },
    getcateid(ret){
        this.setData({
            cate_id:ret.currentTarget.dataset.id
        })
    },
    setdescb2yid(){
        var that=this;
        var cate_id=this.data.cate_id;
        var merch_id=this.data.merch_id;

        api.post({
            url: 'merchlist/setmerchlistcate',
            data: {merch_id:merch_id,cate_id:cate_id},
            success: data => {
                that.getmymerchlist();
                that.setData({
                    wind2:'',
                    cate_id:''
                })
            }
        })
    }

    
});
